﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;

namespace LicPdaService
{
    public class PDAXmlPrintProcess
    {
        /// <summary>
        /// 4.2成品上架打印 Add By Quinn.Ling 201703
        /// DataSource:Inventory
        /// </summary>
        public static string GetPDAPrintData(XmlDocument doc)
        {
            #region 通用变量定义
            string docResult = string.Empty; //返回值
            string userid = string.Empty;
            string whseid = string.Empty;
            string asn = string.Empty;
            string master_label = string.Empty;
            string serial = string.Empty;
            string storage = string.Empty;
            string check = "false";
            string sku = string.Empty;
            string lottable02 = string.Empty;
            string lottable01 = string.Empty;
            string pre_qty = string.Empty;
            string lottable10 = string.Empty;
            string lsline_no = string.Empty;
            string lsdesc = string.Empty;
            string lsunit = string.Empty;
            string lsinvoice_no = string.Empty;
            string lslottable01 = string.Empty;
            string lslottable02 = string.Empty;
            string lslottable03 = string.Empty;
            string lslottable04 = string.Empty;
            string lslottable05 = string.Empty;
            string lslottable06 = string.Empty;
            string lslottable07 = string.Empty;
            string lslottable08 = string.Empty;
            string lslottable09 = string.Empty;
            string lslottable10 = string.Empty;
            string lpn = string.Empty;
            string return_status = string.Empty;
            string page = string.Empty;
            string lspn = string.Empty;
            string lsputaway_no = string.Empty;
            string lscustomer_code = string.Empty;
            string holdno = string.Empty;
            string lot = string.Empty;
            string udf1 = string.Empty;
            string udf2 = string.Empty;
            string udf3 = string.Empty;
            string tray = string.Empty;
            string udf4 = string.Empty;
            bool Recflag = false;
            string invStatus = "OK";//库存货物状态
            string date_now = string.Empty;
            int lnline_no = 1;
            List<string> sqllists = new List<string>();
            List<string> sqllistsLS = new List<string>();
            string strSql = string.Empty;

            XmlDocument docreturn = new XmlDocument();//返回报文
            XmlDeclaration dec = docreturn.CreateXmlDeclaration("1.0", "utf-8", null);//建立Xml的定义声明  
            docreturn.AppendChild(dec);
            XmlElement rootResult = docreturn.CreateElement("NewDataSet"); //创建根节点
            #endregion

            try
            {
                #region
                //App.ws = new Fcl.WSOP.sqldbop();
                //App.ws.Init(System.Configuration.ConfigurationManager.ConnectionStrings["adpwmsConnectionString"].ConnectionString);
                XmlNode root = doc.DocumentElement; // 报文根节点
                XmlNodeList rootlist = root.ChildNodes;
                XmlNode nodewh = root.SelectSingleNode("print");
                whseid = nodewh.SelectSingleNode("whseid").InnerText;
                asn = nodewh.SelectSingleNode("asn").InnerText;
                App.swhseid = whseid;
                App.sasn = asn;

                //strSql = "SELECT receiptkey FROM ReceiptDetail WHERE receiptkey='" + asn + "'";
                strSql = "SELECT MAX(line_no) AS line_no FROM [LicWMS].[dbo].[ReceiptDetail] WHERE   receiptkey='" + asn + "' and whseid='" + whseid + "'";
                DataTable dtcount = App.GetDataTable(App.DBconWMS, strSql, "Sku");
                if (dtcount.Rows.Count > 0)
                {
                    //lnline_no = dtcount.Rows.Count;
                    lnline_no = Int32.Parse(dtcount.Rows[0]["line_no"].ToString()); //new 更新
                }
                strSql = "DECLARE @key varchar(50) exec pro_GetLpn '" + whseid + "','PLT','托盘号',@key OUTPUT select @key as lpn";
                DataTable dtPro = App.GetDataTable(App.DBconWMS, strSql, "Sku");
                if (dtPro.Rows.Count > 0)
                {
                    lspn = dtPro.Rows[0]["lpn"].ToString();
                }

                strSql = "select putaway_no from recputawaydetail where receiptkey='" + asn + "' ";
                DataTable ldtputaway_no = App.GetDataTable(App.DBconWMS, strSql, "Sku");

                if (ldtputaway_no.Rows.Count == 0)
                {
                    strSql = "DECLARE @key varchar(50) exec pro_GetLot '" + whseid + "','PUTAWAY','上架任务编号',@key OUTPUT select @key as putaway"; //调用存储过程pro_GetLpn生成托盘号;
                    DataTable dtLot = App.GetDataTable(App.DBconWMS, strSql, "Sku");
                    if (dtLot.Rows.Count > 0)
                    {
                        lsputaway_no = dtLot.Rows[0]["putaway"].ToString();
                    }
                }
                else
                {
                    lsputaway_no = ldtputaway_no.Rows[0]["putaway_no"].ToString();
                }
                #endregion

                for (int i = 0; i < rootlist.Count; i++)
                {
                    XmlNode nodeSku = rootlist[i];

                    #region 参数源
                    userid = nodeSku.SelectSingleNode("userid").InnerText;
                    whseid = nodeSku.SelectSingleNode("whseid").InnerText;
                    serial = nodeSku.SelectSingleNode("serial").InnerText;
                    storage = nodeSku.SelectSingleNode("storage").InnerText;
                    check = nodeSku.SelectSingleNode("check").InnerText;
                    #endregion

                    #region 获取对应asn,master_label
                    strSql = "SELECT receiptkey,sku,lottable02,lottable01,pre_qty,lottable10 FROM ReceiptDetail WHERE udf1='" + serial + "' and receiptkey='"+asn+ "' and pre_qty>0";
                    DataTable dtsku = App.GetDataTable(App.DBconWMS, strSql, "Sku");
                    if (dtsku.Rows.Count > 0)
                    {
                        if(dtsku.Rows.Count > 1)
                        {
                            strSql = "SELECT Top 1 D.receiptkey,sku,lottable02,lottable01,pre_qty,lottable10 FROM ReceiptDetail  AS D";
                            strSql += " LEFT JOIN Receipt AS H ON D.whseid=H.whseid AND D.receiptkey=H.receiptkey";
                            strSql += " WHERE D.udf1='" + serial + "' and LTRIM(RTRIM(data_from)) !='CMS' and pre_qty>0 and D.status IN ('01','02','03','04','05')";
                            DataTable dtskuTwo = App.GetDataTable(App.DBconWMS, strSql, "Sku");
                            if (dtskuTwo.Rows.Count > 0)
                            {
                                sku = dtskuTwo.Rows[0]["sku"].ToString();
                                pre_qty = dtskuTwo.Rows[0]["pre_qty"].ToString();
                                pre_qty = pre_qty.Substring(0, pre_qty.Length - 3);
                                //asn = dtskuTwo.Rows[0]["receiptkey"].ToString();
                                master_label = dtskuTwo.Rows[0]["sku"].ToString() + "|" + dtskuTwo.Rows[0]["lottable02"].ToString() + "|" + dtskuTwo.Rows[0]["lottable01"].ToString() + "|" + dtskuTwo.Rows[0]["pre_qty"].ToString() + "|" + dtskuTwo.Rows[0]["lottable10"].ToString();
                            }
                            else
                            {
                                sku = dtsku.Rows[0]["sku"].ToString();
                                pre_qty = dtsku.Rows[0]["pre_qty"].ToString();
                                pre_qty = pre_qty.Substring(0, pre_qty.Length - 3);
                                //asn = dtsku.Rows[0]["receiptkey"].ToString();
                                master_label = dtsku.Rows[0]["sku"].ToString() + "|" + dtsku.Rows[0]["lottable02"].ToString() + "|" + dtsku.Rows[0]["lottable01"].ToString() + "|" + dtsku.Rows[0]["pre_qty"].ToString() + "|" + dtsku.Rows[0]["lottable10"].ToString();
                            }
                        }
                        else
                        {
                            sku = dtsku.Rows[0]["sku"].ToString();
                            pre_qty = dtsku.Rows[0]["pre_qty"].ToString();
                            pre_qty = pre_qty.Substring(0, pre_qty.Length - 3);
                            //asn = dtsku.Rows[0]["receiptkey"].ToString();
                            master_label = dtsku.Rows[0]["sku"].ToString() + "|" + dtsku.Rows[0]["lottable02"].ToString() + "|" + dtsku.Rows[0]["lottable01"].ToString() + "|" + dtsku.Rows[0]["pre_qty"].ToString() + "|" + dtsku.Rows[0]["lottable10"].ToString();
                        }
                    }
                    else
                    {
                        asn = "asn获取失败";
                        master_label = "master_label获取失败";
                        return_status = "信息获取失败";
                    }
                    #endregion

                    strSql = "select * from  ReceiptDetail where whseid='" + whseid + "' and receiptkey='" + asn + "' and  udf1='" + serial + "'  AND status IN ('01','02','03')";
                    DataTable ldt_asn_detail = App.GetDataTable(App.DBconWMS, strSql, "Sku");
                    DataRow[] ldrs = ldt_asn_detail.Select("");
                    if (ldrs.Length > 0)
                    {
                        #region 参数源
                        lsline_no = ldrs[0]["line_no"].ToString();
                        lsdesc = ldrs[0]["skudescr"].ToString();
                        lsunit = ldrs[0]["uom"].ToString();
                        lsinvoice_no = ldrs[0]["invoice_no"].ToString();
                        lslottable01 = ldrs[0]["lottable01"].ToString();
                        lslottable02 = ldrs[0]["lottable02"].ToString();
                        lslottable03 = ldrs[0]["lottable03"].ToString();
                        lslottable04 = ldrs[0]["lottable04"].ToString();
                        lslottable05 = ldrs[0]["lottable05"].ToString();
                        lslottable06 = ldrs[0]["lottable06"].ToString();
                        lslottable07 = ldrs[0]["lottable07"].ToString();
                        lslottable08 = ldrs[0]["lottable08"].ToString();
                        lslottable09 = ldrs[0]["lottable09"].ToString();   //包装键
                        lslottable10 = ldrs[0]["lottable10"].ToString();   //供应商代码
                        lpn = ldrs[0]["lpn"].ToString();
                        lscustomer_code = ldrs[0]["customer_code"].ToString();
                        udf1= ldrs[0]["udf1"].ToString();
                        udf2 = ldrs[0]["udf2"].ToString();
                        udf3 = ldrs[0]["udf3"].ToString();
                        tray = ldrs[0]["tray"].ToString().Trim();
                        if (tray.Trim().Length > 0)
                        {
                            tray = tray.Substring(0, tray.Length - 3);
                        }

                        lnline_no += 1;
                        #endregion

                        //判定库位合法性
                        strSql = "SELECT loc FROM [dbo].[Location] where loc='" + storage + "'  AND whseid='" + whseid + "'";
                        DataTable dtloc = App.GetDataTable(App.DBconWMS, strSql, "LOC");
                        if (dtloc.Rows.Count <= 0)
                        {
                            return_status = "上架失败-库位不合法导致！！！ 可能原因：1、库位" + storage + "无效  2、扫描库位不隶属登录账号所在的厂别" + whseid;
                            App.Log("PDAXmlPrintProcess-上架失败-库位不合法导致", strSql);
                        }
                        else
                        {
                            try
                            {
                                #region 上架打印分配库位
                                //确认OK
                                strSql = "insert into receiptdetail(whseid,receiptkey,line_no,customer_code,sku,skudescr,loc,udf1,udf2,udf3,tray,lpn,pre_qty,act_qty,check_qty,goodqty,ngqty,waitqty,unrec_qty,uom,lottable01,lottable02,lottable03,lottable04,lottable05";
                                strSql += ",lottable06,lottable07,lottable08,lottable09,lottable10,invoice_no,addwho,adddate) values( ";
                                strSql += "'" + whseid + "','" + asn + "','" + lnline_no.ToString().PadLeft(5, '0') + "','" + lscustomer_code + "','" + sku + "','" + lsdesc + "','" + storage + "','"+udf1+"','"+udf2+"','"+udf3+"','"+tray+"'";
                                strSql += ",'" + lspn + "',0," + pre_qty + "," + pre_qty + "," + pre_qty + ",0,0," + pre_qty + ",'" + lsunit + "','" + lslottable01 + "','" + lslottable02 + "','" + lslottable03 + "'";
                                strSql += ",'" + lslottable04 + "','" + lslottable05 + "','" + lslottable06 + "','" + lslottable07 + "','" + lslottable08 + "','" + lslottable09 + "','" + lslottable10 + "','" + lsinvoice_no + "','" + userid + "','" + System.DateTime.Now.ToString() + "')";
                                sqllists.Add(strSql);

                                //确认OK
                                strSql = "SELECT putaway_no FROM RecPutaway where whseid='"+whseid+"' and   putaway_no='" + lsputaway_no + "'";
                                DataTable lpnPro = App.GetDataTable(App.DBconWMS, strSql, "Sku");
                                if (lpnPro.Rows.Count <= 0)
                                {
                                    strSql = "INSERT INTO RecPutaway VALUES('" + whseid + "','" + lsputaway_no + "','1','0','" + userid + "',GETDATE(),'')";
                                    sqllists.Add(strSql);
                                }

                                //确认OK
                                strSql = "insert into recputawaydetail(whseid,putaway_no,receiptkey,customer_code,line_no,sku,lottable01,loc,lpn,qty,addwho,adddate,product,status) values ";
                                strSql += "('" + whseid + "','" + lsputaway_no + "','" + asn + "','" + lscustomer_code + "','" + lnline_no.ToString().PadLeft(5, '0') + "','" + sku + "','" + lslottable01 + "','" + storage + "','" + lspn + "'," + pre_qty + ",'" + userid + "','" + DateTime.Now.ToString() + "',1,0)";
                                sqllists.Add(strSql);

                                //确认OK        
                                strSql = "update receiptdetail set status='04',act_qty=pre_qty where whseid='" + whseid + "' and receiptkey='" + asn + "' and line_no='" + lsline_no + "' ";
                                sqllists.Add(strSql);

                                //确认OK
                                strSql = "update receipt set status='04'" + " where whseid='" + whseid + "' and receiptkey='" + asn + "'  ";
                                sqllists.Add(strSql);

                                #endregion

                                #region 上架入账确认完成
                                //新增 上架入账确认完成确认
                                if (App.ExecuteSQLScriptLists(sqllists, App.DBconWMS))
                                {
                                    sqllists.Clear();
                                    strSql = @"select receiptdetail.customer_code, receiptdetail.receiptkey,receiptdetail.sku,receiptdetail.skudescr,line_no,receiptdetail.loc,receiptdetail.lpn, 
                                            receiptdetail.goodqty,receiptdetail.ngqty,receiptdetail.waitqty,receiptdetail.check_qty,receiptdetail.pre_qty,receiptdetail.act_qty,receiptdetail.unrec_qty,receiptdetail.uom,
                                            receiptdetail.lottable01,receiptdetail.lottable02,receiptdetail.lottable03,receiptdetail.lottable04,receiptdetail.lottable05,receiptdetail.lottable06,receiptdetail.lottable07,receiptdetail.lottable08,receiptdetail.lottable09,receiptdetail.lottable10,
                                            receiptdetail.tray,receipt.type,receipt.product,receiptdetail.udf1,receiptdetail.udf2,receiptdetail.udf3,receiptdetail.tray,receiptdetail.invoice_no,sku.test,receipt.udf4 
                                            from receiptdetail
                                            left join receipt on receipt.receiptkey = receiptdetail.receiptkey and receipt.whseid = receiptdetail.whseid
                                            left join sku on  sku.whseid = receiptdetail.whseid and sku.customer_code = receiptdetail.customer_code and sku.sku = receiptdetail.sku
                                            where receiptdetail.whseid = '" + whseid + "' and receiptdetail.receiptkey = '" + asn + "'  and loc!= '' AND receiptdetail.udf1='"+ serial + "' AND ReceiptDetail.status<'06'   order by receiptdetail.line_no";
                                    DataTable actDt = App.GetDataTable(App.DBconWMS, strSql, "Sku");
                                    if (actDt.Rows.Count == 1)
                                    {
                                        for (int j = 0; j < actDt.Rows.Count; j++)
                                        {
                                            strSql = "DECLARE @key varchar(50) exec pro_GetOrderNo '" + whseid + "','FR','holdno','冻结编号',@key OUTPUT select @key as holdno ";
                                            DataTable holdPro = App.GetDataTable(App.DBconWMS, strSql, "Sku");
                                            if (holdPro.Rows.Count > 0)
                                            {
                                                holdno = holdPro.Rows[0]["holdno"].ToString();//调用存储过程pro_GetOrderNo生成工作编号
                                            }
                                            strSql = "DECLARE @key varchar(50) exec pro_GetLot '" + whseid + "','lot','批号',@key OUTPUT select @key as lot";
                                            DataTable lotPro = App.GetDataTable(App.DBconWMS, strSql, "Sku");
                                            if (lotPro.Rows.Count > 0)
                                            {
                                                lot = lotPro.Rows[0]["lot"].ToString();//调用存储过程pro_GetLpn生成批次号;
                                            }
                                            strSql = "select   CONVERT(varchar(100), GETDATE(), 120)  AS datenow";
                                            DataTable datetPro = App.GetDataTable(App.DBconWMS, strSql, "Sku");
                                            if (datetPro.Rows.Count > 0)
                                            {
                                                date_now = datetPro.Rows[0]["datenow"].ToString();
                                            }

                                            ////InvHold为原料待检表，无需写入 - 取消执行
                                            //strSql = "insert into InvHold(holdno,whseid,workorder_no,loc,lot,lpn,status,whohold,holdedate) values";
                                            //strSql += "('" + holdno + "','" + whseid + "','','" + storage + "','" + lot + "','" + lspn + "','1','" + userid + "',GETDATE())";
                                            //sqllists.Add(strSql);

                                            strSql = "insert into Inventory(whseid,customer_code,sku,skudescr,loc,lot,lpn,status,qty,uom,tray) values ";
                                            strSql += "('" + whseid + "','" + actDt.Rows[j]["customer_code"].ToString() + "','" + actDt.Rows[j]["sku"].ToString() + "','" + actDt.Rows[j]["skudescr"].ToString() + "','" + storage + "'";
                                            strSql += ",'" + lot + "','" + actDt.Rows[j]["lpn"].ToString() + "','" + invStatus + "'," + double.Parse(actDt.Rows[j]["act_qty"].ToString()) + ",'" + actDt.Rows[j]["uom"].ToString() + "','" + actDt.Rows[j]["tray"].ToString() + "')";
                                            sqllists.Add(strSql);

                                            tray = actDt.Rows[j]["tray"].ToString().Trim();
                                            if (tray.Trim().Length > 0)
                                            {
                                                tray = tray.Substring(0,tray.Length-3);
                                            }
                                            strSql = "insert into LotAttribute(whseid,customer_code,sku,skudescr,lot,lottable01,lottable02,lottable03,lottable04,lottable05,lottable06,lottable07,lottable08,lottable09,lottable10,rectype,udf1,udf2,udf3,tray,bol,invoice_no,product,addwho,adddate) values ";
                                            strSql += "('" + whseid + "','" + actDt.Rows[j]["customer_code"].ToString() + "','" + actDt.Rows[j]["sku"].ToString() + "','" + actDt.Rows[j]["skudescr"].ToString() + "','" + lot + "','" + actDt.Rows[j]["lottable01"].ToString() + "'";
                                            strSql += ",'" + actDt.Rows[j]["lottable02"].ToString() + "','" + actDt.Rows[j]["lottable03"].ToString() + "','" + date_now + "','" + actDt.Rows[j]["lottable05"].ToString() + "','" + actDt.Rows[j]["lottable06"].ToString() + "'";
                                            strSql += ",'" + actDt.Rows[j]["lottable07"].ToString() + "','" + actDt.Rows[j]["lottable08"].ToString() + "','" + actDt.Rows[j]["lottable09"].ToString() + "','" + actDt.Rows[j]["lottable10"].ToString() + "'";
                                            strSql += ",'" + actDt.Rows[j]["type"].ToString() + "','" + serial + "','" + actDt.Rows[j]["udf2"].ToString() + "','" + actDt.Rows[j]["udf3"].ToString() + "',CASE '" + tray + "' WHEN '' THEN 0 ELSE '" + tray + "' END,'" + actDt.Rows[j]["udf4"].ToString() + "','" + actDt.Rows[j]["invoice_no"].ToString() + "','" + actDt.Rows[j]["product"].ToString() + "','" + userid + "','" + date_now + "')";
                                            sqllists.Add(strSql);

                                            strSql = "update receiptdetail set status='06',lot='" + lot + "',unrec_qty=unrec_qty-" + double.Parse(actDt.Rows[j]["act_qty"].ToString()) + ",lottable04='" + date_now + "'  where whseid='" + whseid + "' and receiptkey='" + asn + "' and line_no='" + actDt.Rows[j]["line_no"].ToString() + "'";
                                            sqllists.Add(strSql); //收货日期默认当前接收日期

                                            string recstatus = "06";
                                            double uqty = 0; //pre_qty - unRec_qty;

                                            strSql = "update receiptdetail set status='" + recstatus + "', act_qty=pre_qty,unrec_qty=0,lottable04='" + date_now + "' where whseid='" + whseid + "' and receiptkey='" + asn + "' and lottable03='" + actDt.Rows[j]["lottable03"].ToString() + "' and (loc='' or loc is null) ";
                                            sqllists.Add(strSql);

                                            string statusMain = "06";
                                            strSql = "update receipt set status='" + statusMain + "',act_receiptdate='" + date_now + "' where whseid='" + whseid + "' and receiptkey='" + asn + "'";
                                            sqllists.Add(strSql);
                                            strSql = "insert into RecHistory(whseid,receiptkey,status,operation,addwho,adddate) values";
                                            strSql += "('" + whseid + "','" + asn + "','" + statusMain + "','全部接收','" + userid + "','" + DateTime.Now.ToString() + "')";
                                            sqllists.Add(strSql);

                                            strSql = "update recputaway set status='1',enddate='" + date_now + "' where whseid='" + whseid + "' and putaway_no='" + lsputaway_no + "'";
                                            sqllists.Add(strSql);

                                            strSql = "update RecPutawayDetail set status='1' where whseid='" + whseid + "' and putaway_no='" + lsputaway_no + "'";
                                            sqllists.Add(strSql);
                                        }
                                    }
                                    else
                                    {
                                        return_status = "成品上架入账确认失败！！！请前往PC端重新执行入账确认完成操作。 可能原因：1、Serail号" + serial + "已上架，不可重复上架 2、无可入账信息  3、Serail号" + serial + "重复";
                                        App.Log("PDAXmlPrintProcess-成品上架成功，但入账完成确认失败1.1", "可能原因：1、无可入账信息  2、Serail号"+ serial + "重复  3、Serail号" + serial + "重复上架");
                                    }

                                    if (!App.ExecuteSQLScriptLists(sqllists, App.DBconWMS))
                                    {
                                        return_status = "成品上架成功，但入账完成确认失败！！！请前往PC端重新执行入账确认完成操作。 原因：入账数据无法提交";
                                        App.Log("PDAXmlPrintProcess-成品上架成功，但入账完成确认失败1.2", "原因：入账数据无法提交");
                                    }
                                }
                                else
                                {
                                    return_status = "成品上架&入账确认 失败！！！ 原因：上架/入账数据无法提交";
                                    App.Log("PDAXmlPrintProcess-成品上架&入账确认 失败1.1", "原因：上架/入账数据无法提交");
                                }
                                #endregion
                            }
                            catch (Exception ex)
                            {
                                return_status = "成品上架&入账确认 失败！！！ 原因："+ex.Message.ToString();
                                App.Log("PDAXmlPrintProcess-成品上架&入账确认 失败1.2", ex.Message.ToString());
                            }
                        }
                    }
                    else
                    {
                        return_status = "成品上架&入账确认 失败！！！ 可能原因：1、没有待上架信息 2、此ASN单号："+asn+"下的Serial号："+serial+"已上架，不可重复上架!!!";
                        App.Log("PDAXmlPrintProcess-成品上架&入账确认 失败1.2", "可能原因：1、没有待上架信息 2、此单已上架，不可重复上架");
                    }

                    #region 构建XML报文
                    XmlNode print_result = docreturn.CreateElement("print_return");

                    XmlElement useridResult = docreturn.CreateElement("userid");
                    useridResult.InnerText = userid;
                    print_result.AppendChild(useridResult);

                    XmlElement whseidResult = docreturn.CreateElement("whseid");
                    whseidResult.InnerText = whseid;
                    print_result.AppendChild(whseidResult);

                    XmlElement asnResult = docreturn.CreateElement("asn");
                    asnResult.InnerText = asn;
                    print_result.AppendChild(asnResult);

                    XmlElement serialResult = docreturn.CreateElement("serial");
                    serialResult.InnerText = serial;
                    print_result.AppendChild(serialResult);

                    XmlElement skuResult = docreturn.CreateElement("sku");
                    skuResult.InnerText = sku;
                    print_result.AppendChild(skuResult);

                    XmlElement batchResult = docreturn.CreateElement("batch");
                    batchResult.InnerText = lslottable01;
                    print_result.AppendChild(batchResult);

                    XmlElement qtyResult = docreturn.CreateElement("qty");
                    qtyResult.InnerText = pre_qty;
                    print_result.AppendChild(qtyResult);

                    XmlElement storageResult = docreturn.CreateElement("storage");
                    storageResult.InnerText = storage;
                    print_result.AppendChild(storageResult);

                    XmlElement lpnResult = docreturn.CreateElement("lpn");
                    lpnResult.InnerText = lpn;
                    print_result.AppendChild(lpnResult);

                    XmlElement return_statusResult = docreturn.CreateElement("return_status");
                    return_statusResult.InnerText = return_status;
                    print_result.AppendChild(return_statusResult);

                    page = Math.Ceiling(Convert.ToDecimal(i + 1) / 1).ToString();
                    XmlElement pageResult = docreturn.CreateElement("page");
                    pageResult.InnerText = page;
                    print_result.AppendChild(pageResult);

                    rootResult.AppendChild(print_result);
                    #endregion
                }

                #region 独立数据补更新
                //确认OK
                if (ldtputaway_no.Rows.Count == 0)
                {
                    try
                    {
                        sqllists.Clear();
                        strSql = "insert into RecPutaway(whseid,putaway_no, product,status,addwho,adddate) values ";
                        strSql += "('" + whseid + "','" + lsputaway_no + "',1,0,'" + userid + "','" + DateTime.Now.ToString() + "')";
                        sqllists.Add(strSql);
                        App.ExecuteSQLScriptLists(sqllists, App.DBconWMS);
                    }
                    catch (Exception ex)
                    {
                        App.Log("PDAXmlPrintProcess-独立数据更新失败1.1", strSql);
                    }
                }
                #endregion
            }
            catch (Exception ex)
            {
                App.Log("PDAXmlPrintProcess", ex.Message.ToString());
            }

            docreturn.AppendChild(rootResult);
            return docreturn.InnerXml;

        }
    }
}
